<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        /**
         * @param {number} n
         * @return {number}
         */
        var cuttingRope = function(n) {
            //声明一个数组保存当线的长度小于5时的结果
            let arr = [0, 0, 1, 2, 4];
            if (n < 5) return arr[n];
            const max = 1e9 + 7; //1000000007
            let res = 1;
            while (n >= 5) {
                res = res % max * 3;
                n = n - 3;
            }
            return res * n % max;
        };
    </script>
</body>

</html>